<template>
  <div 
    class="header-container" 
    :style="{ 
      background: isScrolled ? 'white' : 'transparent',
      color: isScrolled ? '#333' : customStyle.color
    }"
  >
    <Back :custom-style="{ color: isScrolled ? '#333' : customStyle.color }" />
    <div class="title" :style="{ color: isScrolled ? '#333' : customStyle.color }">
      {{ title }}
    </div>
  </div>
  <div style="height: 40px;"></div>
</template>

<script setup>
import { defineProps, computed, ref, onMounted, onUnmounted } from 'vue'
import Back from './icons/Back.vue'

const props = defineProps({
  title: {
    type: String,
    required: true
  },
  isWhite: {
    type: Boolean,
    default: false
  }
})

const isScrolled = ref(false)

const checkScroll = () => {
  isScrolled.value = window.scrollY > 5
}

onMounted(() => {
  window.addEventListener('scroll', checkScroll)
})

onUnmounted(() => {
  window.removeEventListener('scroll', checkScroll)
})

const customStyle = computed(() => ({
  color: props.isWhite ? 'white' : '#333'
}))
</script>

<style scoped>
.header-container {
  height: 40px;
  width: 100%;
  display: flex;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  padding: 2em 2em 0 2em;
  box-sizing: content-box;
  transition: background 0.3s ease;
}

.title {
  height: 40px;
  line-height: 40px;
  padding-left: 20px;
  transition: color 0.3s ease;
}
</style>